﻿Imports System.Management

Public Class ClsAdapter

    Private strName As String
    Private strManufacturer As String
    Private intTypeId As Integer
    Private bolEnabled As Boolean

    Public Property Name() As String
        Get
            Return strName
        End Get
        Set(ByVal value As String)
            strName = value
        End Set
    End Property

    Public Property Manufacturer() As String
        Get
            Return strManufacturer
        End Get
        Set(ByVal value As String)
            strManufacturer = value
        End Set
    End Property

    Public Property TypeId() As Integer
        Get
            Return intTypeId
        End Get
        Set(ByVal value As Integer)
            intTypeId = value
        End Set
    End Property

    Public Property Enabled() As Boolean
        Get
            Return bolEnabled
        End Get
        Set(ByVal value As Boolean)
            bolEnabled = value
        End Set
    End Property

    Public Shared Function getTypeName(TypeId As Integer) As String
        Select Case TypeId
            Case 0
                Return ("Ethernet 802.3")
            Case 1
                Return ("Token Ring 802.5")
            Case 2
                Return ("Fiber Distributed Data Interface (FDDI)")
            Case 3
                Return ("Wide Area Network (WAN)")
            Case 4
                Return ("LocalTalk")
            Case 5
                Return ("Ethernet using DIX header format")
            Case 6
                Return ("ARCNET")
            Case 7
                Return ("ARCNET (878.2)")
            Case 8
                Return ("ATM")
            Case 9
                Return ("Wireless")
            Case 10
                Return ("Infrared Wireless")
            Case 11
                Return ("Bpc")
            Case 12
                Return ("CoWan")
            Case 13
                Return ("1394")
            Case Else
                Return ("Unknown adapter type [" & TypeId & "]")
        End Select
    End Function

    Public Shared Function getAdapter() As Collection
        Dim WQLQuery As WqlObjectQuery
        Dim Searcher As ManagementObjectSearcher
        Dim Adapter As ManagementObject
        Dim ColAdapter As New Collection

        WQLQuery = New WqlObjectQuery("SELECT * FROM Win32_NetworkAdapter WHERE manufacturer<>'Microsoft'")
        Searcher = New ManagementObjectSearcher(WQLQuery)

        For Each Adapter In Searcher.Get()
            Dim NewAdapter As New ClsAdapter
            NewAdapter.Name = Adapter.Properties("Description").Value
            NewAdapter.intTypeId = Adapter.Properties("AdapterTypeID").Value
            NewAdapter.Enabled = Adapter.Properties("NetEnabled").Value
            Try
                NewAdapter.Manufacturer = Adapter.Properties("Manufacturer").Value
            Catch ex As Exception
                NewAdapter.Manufacturer = "No manufacturer information"
            End Try

            ColAdapter.Add(NewAdapter)
        Next

        Return ColAdapter
    End Function
End Class
